﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Windows;
using System.Windows.Input;
using PSSMS.Tools.Utils;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PSSMS.View.SysManage;
using PSSMS.MainWindowView.Resources;
using System.Windows.Threading;
using PSSMS.View.AccPay;

namespace PSSMS
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        private DispatcherTimer showtimer;
        public Window1()
        {
            InitializeComponent();
        }
        #region 全局变量
        static TabControl TC;//静态选项卡
        UserControl UC = null;//容器要嵌套的界面
        int intDownTag = 0;//当前选择的按钮的tag
        /// <summary>
        /// 定义一个全局rect记录还原状态下窗口的位置和大小。
        /// </summary>
        Rect rectNormal;

        public string StrModularDetailID { get; }
        #endregion
        private void Wind_Loaded(object sender, RoutedEventArgs e)
        {
            //获取选显卡
            TC = tab_Main;
        }

        #region 窗口（放大、缩小、退出）
        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Img_Min_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Wind.WindowState = WindowState.Minimized;
        }
        Rect rcnormal;//定义一个全局rect记录还原状态下窗口的位置和大小。

        /// <summary>
        /// 最大化/还原标记（默认还原）
        /// </summary>
        bool ismax = false;

        /// <summary>
        /// 最大化/还原
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Img_Normal_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            this.Left = rectNormal.Left;
            this.Top = rectNormal.Top;
            this.Width = rectNormal.Width;
            this.Height = rectNormal.Height;
            this.Img_Max.Visibility = Visibility.Visible;
            this.Img_Normal.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// 全屏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Img_Max_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Img_Max.Visibility = Visibility.Collapsed;
            this.Img_Normal.Visibility = Visibility.Visible;
            rcnormal = new Rect(this.Left, this.Top, this.Width, this.Height);//保存下当前位置与大小
            this.Left = 0;//设置位置
            this.Top = 0;
            Rect rc = SystemParameters.WorkArea;//获取工作区大小
            this.Width = rc.Width;
            this.Height = rc.Height;
        }

        /// <summary>
        /// 退出系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_tuichu_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("你确定要退出系统吗？", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                Application.Current.Shutdown();
            }
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Img_Exit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }
        #endregion

        /// <summary>
        /// 控制二级菜单展示和隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Warehousing(object sender, RoutedEventArgs e)
        {
            //嵌套菜单
            //（1）判断按钮是不是重复选择        
            if (intDownTag == Convert.ToInt32(((RadioButton)sender).Tag))
            {

                if (((RadioButton)sender) == btnSystemInformation)
                {
                    //控制【入库管理】菜单组件隐藏
                    btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                }
                else if (((RadioButton)sender) == btnTrainOrder)
                {
                    //控制【出库管理】菜单组件隐藏
                    btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                }
                else if (((RadioButton)sender) == btnLineManage)
                {
                    //控制【库存管理】菜单组件隐藏
                    btnLineManageBorder.Visibility = Visibility.Collapsed;
                }
                else if (((RadioButton)sender) == btnTicketTask)
                {
                    //控制【统计报表】菜单组件隐藏
                    btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                }
                else if (((RadioButton)sender) == btnDataStatistics)
                {
                    //控制【往来账款】菜单组件隐藏
                    btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                }
                else if (((RadioButton)sender) == btnSystemsetup)
                {
                    //控制【系统设置】菜单组件隐藏
                    SystemsetupBorder.Visibility = Visibility.Collapsed;
                }
                //调整左边菜单栏的显示和隐藏
                intDownTag = 0;
                return;
            }
            //（2）展开点击按钮的二级菜单，其他按钮的二级菜单隐藏
            else if (((RadioButton)sender) == btnSystemInformation)
            {
                //控制【入库管理】菜单组件显示
                btnSystemInformationBorder.Visibility = Visibility.Visible;
                //控制【出库管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【库存管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【统计报表】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【往来账款】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                //控制【系统设置】菜单组件隐藏
                SystemsetupBorder.Visibility = Visibility.Collapsed;
            }
            else if (((RadioButton)sender) == btnTrainOrder)
            {
                //控制【入库管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【出库管理】菜单组件显示
                btnTrainOrderBorder.Visibility = Visibility.Visible;
                //控制【库存管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【统计报表】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【往来账款】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                //控制【系统设置】菜单组件隐藏
                SystemsetupBorder.Visibility = Visibility.Collapsed;
            }
            else if (((RadioButton)sender) == btnLineManage)
            {
                //控制【入库管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【出库管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【库存管理】菜单组件显示
                btnLineManageBorder.Visibility = Visibility.Visible;
                //控制【统计报表】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【往来账款】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                //控制【系统设置】菜单组件隐藏
                SystemsetupBorder.Visibility = Visibility.Collapsed;
            }
            else if (((RadioButton)sender) == btnTicketTask)
            {
                //控制【入库管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【出库管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【库存管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【统计报表】菜单组件显示
                btnTicketTaskBorder.Visibility = Visibility.Visible;
                //控制【往来账款】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                //控制【系统设置】菜单组件隐藏
                SystemsetupBorder.Visibility = Visibility.Collapsed;
            }
            else if (((RadioButton)sender) == btnDataStatistics)
            {
                //控制【入库管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【出库管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【库存管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【统计报表】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【往来账款】菜单组件显示
                btnDataStatisticsBorder.Visibility = Visibility.Visible;
                //控制【系统设置】菜单组件隐藏
                SystemsetupBorder.Visibility = Visibility.Collapsed;
            }
            else if (((RadioButton)sender) == btnSystemsetup)
            {
                //控制【入库管理】菜单组件隐藏
                btnSystemInformationBorder.Visibility = Visibility.Collapsed;
                //控制【出库管理】菜单组件隐藏
                btnTrainOrderBorder.Visibility = Visibility.Collapsed;
                //控制【库存管理】菜单组件隐藏
                btnLineManageBorder.Visibility = Visibility.Collapsed;
                //控制【统计报表】菜单组件隐藏
                btnTicketTaskBorder.Visibility = Visibility.Collapsed;
                //控制【往来账款】菜单组件隐藏
                btnDataStatisticsBorder.Visibility = Visibility.Collapsed;
                //控制【系统设置】菜单组件显示
                SystemsetupBorder.Visibility = Visibility.Visible;
            }
            //当前选择按钮的Tag
            intDownTag = Convert.ToInt32(((RadioButton)sender).Tag);
        }

        #region 用户控件嵌套
        /// <summary>
        /// 给选项卡添加选项
        /// </summary>
        public static void AddTabItem(string strName, UserControl control)
        {
            bool blCheck = false;//用于区分是否重复选择
            //判断选项卡是否有内容
            if (TC.Items.Count > 0)
            {
                //选项卡有选项：
                //（2）循环判断是否重复选择
                for (int i = 0; i < TC.Items.Count; i++)
                {
                    if (((UCTabItemWithClose)TC.Items[i]).Name == strName)
                    {
                        //重复选择
                        TC.SelectedItem = (UCTabItemWithClose)TC.Items[i];
                        blCheck = true;//重复
                        break;//打破循环
                    }
                }
                if (blCheck == false)
                {
                    //（2）不重复选择
                    UCTabItemWithClose tabItem = new UCTabItemWithClose();//创建子选项
                    tabItem.Name = strName;//名称
                    tabItem.Header = string.Format(strName);//标头名称
                    tabItem.Margin = new Thickness(0, 0, 1, 0);
                    tabItem.Content = control;//子选择里面的内容   
                    TC.Items.Add(tabItem);//添加子选项
                    TC.SelectedItem = tabItem;//选中子选项          
                }
            }
            else
            {
                //没有：添加
                UCTabItemWithClose tabItem = new UCTabItemWithClose();//创建子选项
                tabItem.Name = strName;//名称
                tabItem.Header = string.Format(strName);//标头名称
                tabItem.Margin = new Thickness(0, 0, 1, 0);
                tabItem.Content = control;//子选择里面的内容   
                TC.Items.Add(tabItem);//添加子选项
                TC.SelectedItem = tabItem;//选中子选项                

            }
        }
     
        /// <summary>
        /// 系统管理页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void XtglClick(object sender, RoutedEventArgs e)
        {
            SystemManagement mainWindow4 = new SystemManagement();
            mainWindow4.Show();//关闭登录窗口
            this.Close();
        }

        /// <summary>
        /// 商品管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MerchClick(object sender, RoutedEventArgs e)
        {
            SMerchandise mainW = new SMerchandise();
            AddTabItem("商品管理", mainW);
        }
        /// <summary>
        /// 供货商管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void supplierClick(object sender, RoutedEventArgs e)
        {
            ProviderSM sM = new ProviderSM();
            AddTabItem("供货商管理", sM);
        }
        /// <summary>
        /// 客户设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClientClick(object sender, RoutedEventArgs e)
        {
            ClientSM CM = new ClientSM();
            AddTabItem("客户设置", CM);
        }
        /// <summary>
        /// 部门管理--员工设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StaffClick(object sender, RoutedEventArgs e)
        {
            StaffSM stasm = new StaffSM();
            AddTabItem("部门管理", stasm);
        }
        /// <summary>
        /// 操作员设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OperatorClick(object sender, RoutedEventArgs e)
        {
            OperatorSM Opersm = new OperatorSM();
            AddTabItem("操作员设置", Opersm);
        }

        /// <summary>
        /// 采购进货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PurchClick(object sender, RoutedEventArgs e)
        {
            PurchW purchw = new PurchW();
            AddTabItem("采购进货", purchw);
        }

        /// <summary>
        /// 采购退货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void returnClick(object sender, RoutedEventArgs e)
        {
            ReturnW returnw = new ReturnW();
            AddTabItem("采购退货", returnw);
        }

        /// <summary>
        /// 进货管理--往来账务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void accounClick(object sender, RoutedEventArgs e)
        {
            AccountingW accw = new AccountingW();
            AddTabItem("往来账务", accw);
        }
        /// <summary>
        /// 往来账款--应收登记
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void receivableClick(object sender, RoutedEventArgs e)
        {
            Receivableap Opersm = new Receivableap();
            AddTabItem("应收登记", Opersm);
        }
        /// <summary>
        /// 采购入库查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PurWareQuery_Click(object sender, RoutedEventArgs e)
        {
            PurwareQuerap PurQap = new PurwareQuerap();
            AddTabItem("采购入库查询", PurQap);
        }
        /// <summary>
        /// 库存查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InvQuery_Click(object sender, RoutedEventArgs e)
        {
            InvenQuery Inquery = new InvenQuery();
            AddTabItem("库存查询", Inquery);
        }

        /// <summary>
        /// 商品管理--商品销售
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComSales_Click(object sender, RoutedEventArgs e)
        {
            ComSales comsal = new ComSales();
            AddTabItem("商品销售", comsal);
        }
        /// <summary>
        /// 顾客退货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustRets_Click(object sender, RoutedEventArgs e)
        {
            CusReturns cusretu = new CusReturns();
            AddTabItem("顾客退货", cusretu);
        }
        /// <summary>
        /// 商品销售管理查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComSalesInqu_Click(object sender, RoutedEventArgs e)
        {
            ComSalesInqu comsain = new ComSalesInqu();
            AddTabItem("商品销售管理查询", comsain);
        }
        /// <summary>
        /// 库存盘点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StockTak_Click(object sender, RoutedEventArgs e)
        {
            StockTak stotak = new StockTak();
            AddTabItem("库存盘点", stotak);
        }
        #endregion
    }
}
